package com.rjgc.title.controller.apply;

import com.rjgc.title.common.result.Result;
import com.rjgc.title.model.entity.apply.TeachAwards;
import com.rjgc.title.model.entity.apply.TeachingSituation;
import com.rjgc.title.service.TeachAwardsService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @program: title-parent
 * @author: Mr.Zhuo
 * @create: 2022-04-25 23:21
 **/
@Api(tags = "教育教学获奖情况")
@RestController
@RequestMapping("/api/teachawardsc")
public class TeachAwardsController {
    @Autowired
    private TeachAwardsService teachAwardsService;

    /**
     * 保存用户
     * @param request
     * @param teachAwards
     * @return
     */
    @PostMapping("inner/save")
    public Result save(HttpServletRequest request, @RequestBody TeachAwards teachAwards) {
        // 获取当前对象的id
        String userId = (String) request.getSession().getAttribute("userId");
        teachAwards.setUserId(Long.parseLong(userId));
        // 调用service方法进行保存
        teachAwardsService.save(teachAwards);
        return Result.ok();
    }

    /**
     * 根据用户id查询所有
     *
     * @param request
     * @return
     */
    @GetMapping("inner/getAll")
    public Result getAll(HttpServletRequest request) {
        // 获取当前对象的id
        String userId = (String) request.getSession().getAttribute("userId");
        List<TeachAwards> teachAwards  = teachAwardsService.getAll(userId);

        return Result.ok(teachAwards);
    }


    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("inner/getById/{id}")
    public Result getById(@PathVariable("id") Long id) {
        // 调用service方法进行查询
        TeachAwards teachAwards = teachAwardsService.getById(id);

        // 返回数据
        return Result.ok(teachAwards);
    }

    /**
     *  根据id删除
     * @param id
     * @return
     */
    @DeleteMapping("inner/deleteById/{id}")
    public Result deleteById(@PathVariable("id") Long id) {
        // 调用service方法进行查询
        teachAwardsService.removeById(id);

        return Result.ok();
    }

    /**
     * 更新操作
     * @param teachAwards
     * @return
     */
    @PostMapping("inner/updateById")
    public Result updateById(@RequestBody TeachAwards teachAwards) {
        // 调用service方法进行更新
        teachAwardsService.updateById(teachAwards);

        return Result.ok();
    }

}
